<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	template="/WEB-INF/templates/default.xhtml">
	<ui:define name="content">
		<p:outputPanel>
			<h:form id="authorForm">
				<p:watermark for="firstName" value="Firstname" />
				<p:inputText id="firstName" value="#{authorsBackingBean.newAuthor.firstName}" immediate="true" />
				<p:watermark for="lastName" value="Lastname" />
				<p:inputText id="lastName" value="#{authorsBackingBean.newAuthor.lastName}" immediate="true" />
				<p:commandButton action="#{authorsBackingBean.addNewAuthor()}" value="Add author" update=":authorForm" />
				
				<p:dataTable id="allAuthors" var="author" value="#{authorsBackingBean.allAuthors}" >  
  
			        <p:column headerText="Firstname" style="width:100px">  
			            <h:outputText value="#{author.firstName}" />  
			        </p:column>  
			  
			        <p:column headerText="LastName" style="width:100px">  
			            <h:outputText value="#{author.lastName}" />  
			        </p:column>  
			        
			        <p:column headerText="books" style="width:100px">  
			            <p:dataList var="book" value="#{authorsBackingBean.getAllBookFor(author)}">
			            	<h:outputText value="#{book.title}" />
			            </p:dataList>
			        </p:column>
			  
			        <p:column style="width:40px">  
						<p:commandButton id="deleteButton" update=":authorForm" value="Delete" action="#{authorsBackingBean.removeAuthor(author)}"/>   
			        </p:column>
			        
			        <p:column style="width:40px">  
						<p:commandButton id="editButton" value="Edit" action="#{authorsBackingBean.setSelectedAuthor(author)}" oncomplete="editauthorDialogWidget.show()"/>   
			        </p:column>
			  
			    </p:dataTable>  
			
				<p:dialog id="editauthorDialog" widgetVar="editauthorDialogWidget" resizable="false" dynamic="true" >
			  		<h:outputLabel for="editFirstName">Firstname</h:outputLabel>
			  		<p:inputText id="editFirstName" value="#{authorsBackingBean.selectedAuthor.firstName}"/>
			  		<h:outputLabel for="editlasstName">Lastname</h:outputLabel>
			  		<p:inputText id="editlasstName" value="#{authorsBackingBean.selectedAuthor.lastName}"/>
			 		<p:commandButton action="#{authorsBackingBean.updateAuthorInfo()}" value="Update" oncomplete="editauthorDialogWidget.hide()" update="allAuthors"/>
			  	</p:dialog>
			</h:form>
		</p:outputPanel>
	</ui:define>
</ui:composition>
